package com.myproject.thread.interrupt;

public class IsInterruptTest3 {

    public static boolean flag = true;
/*
*三个类的结论：只有当线程清除阻塞状态后再调用一次interrupt,则他的isinterrupt状态会变为true
* */

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("start");
                while (flag){
                    try {
                        Thread.sleep(Integer.MAX_VALUE);
                    } catch (InterruptedException e) {
                    }
                    System.out.println(Thread.currentThread().getName()+ " " +Thread.currentThread().isInterrupted());
                }
                System.out.println("end");
            }
        });
        t1.start();

        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());
    }

}
